package com.turing.data.scripts.xgpsgg.filter

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.turing.common.util.FileUtils
import com.turing.common.util.Log
import com.turing.common.util.StringUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO
import org.apache.ibatis.ognl.internal.Entry

import java.util.regex.Matcher
import java.util.regex.Pattern

class SecuritiesCode_12357_r15_filter {

    public static void main(String[] args) {
        DependParamsVO param = new DependParamsVO()
        param.setJSONPathMap(new LinkedHashMap<String, String>())
//        param.getJSONPathMap().put("abc", "http://media.tlrobot.com/group1/M00/0C/29/rBIHD2CjdRiAPV_eAACdNH_q44831.json")
//        param.getJSONPathMap().put("abc", "/Users/luoshiwei/Desktop/tmp/ex/extractor/e675314b-1c3b-4bb7-9a9f-ef5c268b7b6d/688316_20210305_1/json/688316_20210305_1_converted.json")
        param.getJSONPathMap().put("abc", "C:\\Users\\14771\\Desktop\\342333-20滨海04-缴款通知书_converted.json")
        List<TaskElementVO.DrawResultVO> s = doConvert(param)
        for (int z = 0; z < s.size(); z++) {
            def get = s.get(z)
            println(get.text)
        }
    }

    static List<TaskElementVO.DrawResultVO> doConvert(DependParamsVO dependParams) {
        List<TaskElementVO.DrawResultVO> finalResults = new ArrayList<>()
        def keyWord = /(?<!\d)[0-9]{6}(?!\d)/
        Pattern keyWordPattern = Pattern.compile(keyWord);
        List<String> keys = dependParams.getJSONPathMap().keySet() as List<String>
        //dependParams.fileNames得到的答案是：[983742100644429824:2021-10-19688280.SH-688280贝泰妮：首次公开发行股票并在创业板上市网下发行初步配售结果公告]
        for (int z = 0; z < keys.size(); z++) {
            def pathName = ""
//            def pathName = dependParams.getJSONPathMap().get(keys.get(z))
            Map<String, String> fileNames =dependParams.fileNames
//            Log.info("fileNames得到的原始答案是：" + fileNames)
            try{
                for(String key : fileNames.keySet()){
                    pathName = fileNames.get(key)
                }
//            Log.info("SecuritiesCode得到的原始答案是：" + pathName)
                if(pathName.contains("\\")){
                    pathName = pathName.substring(pathName.lastIndexOf("\\"))
                }
                if(pathName.contains("/")){
                    pathName = pathName.substring(pathName.lastIndexOf("/"))
                }
//                Log.info("SecuritiesCode得到的原始答案是：" + pathName)
                Matcher keyWordmatcher = keyWordPattern.matcher(pathName);
                if (keyWordmatcher.find()){
                    def str = keyWordmatcher.group()
                    TaskElementVO.DrawResultVO drawResultVO = new TaskElementVO.DrawResultVO()
                    drawResultVO.setBusinessValue(str)
                    drawResultVO.setText(str)
                    drawResultVO.setChildTaskSn(keys.get(z))
                    drawResultVO.setType(1)
                    finalResults.add(drawResultVO)
                    return finalResults
                }
            }catch(Exception e){
                Log.error(">>>>>>>>>>>>>>e="+e)
            }

        }

        TaskElementVO.DrawResultVO drawResultVO = new TaskElementVO.DrawResultVO()
        drawResultVO.setBusinessValue("")
        drawResultVO.setText("")
        drawResultVO.setType(1)
        finalResults.add(drawResultVO)
        return finalResults
    }

}
